package cn.itcast.demo.web;

import cn.itcast.demo.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.Arrays;

/**
 * @author 虎哥
 */
@Controller
public class HelloController {

    /**
     * 跳转到hello视图。视图：prefix + viewName + suffix
     * InternalResourceViewResolver
     *  prefix: /WEB-INF/views/
     *  suffix: .jsp
     */
    @GetMapping("hello")
    public String hello(Model model){
        model.addAttribute("msg", "hello, thymeleaf!");

        model.addAttribute("users",
                Arrays.asList(
                        new User("Jack", 21),
                        new User("ZhangHuYi", 21),
                        new User("Rose", 18)
                )
        );
        return "hello";
    }
}
